package com.bs.rocketmq.listen;

import com.alibaba.fastjson.JSON;
import com.bs.rocketmq.vo.UserVo;
import lombok.extern.log4j.Log4j2;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author bingshao
 * @date 2023/5/29
 **/
@Log4j2
@Component
@RocketMQMessageListener(
        topic = "sync-topic",
        consumeMode = ConsumeMode.CONCURRENTLY,
        messageModel = MessageModel.CLUSTERING,
        consumerGroup = "bs-sync-consumer")
public class SyncConsumerListener implements RocketMQListener<MessageExt> {

    @Override
    public void onMessage(MessageExt messageExt) {
        log.info("同步接收到消息=====>{}", JSON.parseObject(new String(messageExt.getBody()), UserVo.class).toString());
    }
}
